﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DoFactory.GangOfFour.Abstract.RealWorld
{
    public class ExampleLuciano
    {
        public void Arrancar()
        {
            IndustriaAnimal argentinaAnimal = new ArgentinaAnimal();
            MundoAnimal mundoAnimal = new MundoAnimal(argentinaAnimal);
            mundoAnimal.EmpezarMundoAnimal();

            Console.WriteLine("Ahora Brasil");
            IndustriaAnimal brasilAnimal = new BrasilAnimal();
            mundoAnimal = new MundoAnimal(brasilAnimal);
            mundoAnimal.EmpezarMundoAnimal();


            Console.ReadKey();
        }
    }

    #region Core

    public abstract class IndustriaAnimal
    {
        public abstract Herbivoro CrearHerbivoro();
        public abstract Carnivoro CrearCarnivor();
    }

    public abstract class TiposAnimales
    {
        protected TiposAnimales()
        {
            Console.WriteLine("Creando: " + this.GetType().Name);
        }
    }

    public abstract class Herbivoro : TiposAnimales
    {

    }


    public abstract class Carnivoro : TiposAnimales
    {
        public abstract void ComerHerbivoro(Herbivoro h);
    }

    class MundoAnimal
    {
        private Herbivoro _herbivoro;
        private Carnivoro _carnivoro;

        public MundoAnimal(IndustriaAnimal ind)
        {
            _herbivoro = ind.CrearHerbivoro();
            _carnivoro = ind.CrearCarnivor();

        }

        public void EmpezarMundoAnimal()
        {
            _carnivoro.ComerHerbivoro(_herbivoro);
        }
    }

    #endregion

    #region Implementation Argentina
    class ArgentinaAnimal : IndustriaAnimal
    {
        public override Herbivoro CrearHerbivoro()
        {
            return new Obeja();
        }

        public override Carnivoro CrearCarnivor()
        {
            return new Yacare();
        }
    }

    public class Obeja : Herbivoro
    {

    }

    public class Yacare : Carnivoro
    {
        public override void ComerHerbivoro(Herbivoro h)
        {
            Console.WriteLine(this.GetType().Name + " Come >>> " + h.GetType().Name);
        }
    }

    #endregion

    #region Implementation Brasil

    public class BrasilAnimal : IndustriaAnimal
    {
        public override Herbivoro CrearHerbivoro()
        {
            return new Monos();
        }

        public override Carnivoro CrearCarnivor()
        {
            return new Anaconda();
        }
    }

    class Anaconda : Carnivoro
    {
        public override void ComerHerbivoro(Herbivoro h)
        {
            Console.WriteLine(this.GetType().Name + " come >>> " + h.GetType().Name);
        }
    }

    class Monos : Herbivoro
    {

    }

    #endregion




}
